package artexercise;

// 算式抽象类
public abstract class ArithmeticExpression {
    protected int operand1;
    protected int operand2;
    protected int result;
    protected String operator;

    public ArithmeticExpression(int operand1, int operand2) {
        this.operand1 = operand1;
        this.operand2 = operand2;
        calculate();
    }

    // 抽象方法，子类必须实现
    public abstract void calculate();

    // 检查算式是否有效（如减法结果不能为负数）
    public abstract boolean isValid();

    // 格式化显示算式
    public String toString() {
        return operand1 + " " + operator + " " + operand2 + " = ";
    }

    // 获取完整算式（带结果）
    public String toFullString() {
        return operand1 + " " + operator + " " + operand2 + " = " + result;
    }

    // Getters
    public int getOperand1() { return operand1; }
    public int getOperand2() { return operand2; }
    public int getResult() { return result; }
    public String getOperator() { return operator; }
}

